(ns blade-art-online.db.user
  (:require [blade-art-online.db.common :as common]))


(defn insert-user 
  "插入user or 抛出异常"
  ([user]
    (insert-user user (common/coon)))

  ([{:keys [name pass]} coon]
    (let [stat (. coon createStatement)]
        (. stat executeUpdate 
          (str "insert into user(name,pass) values ('" name "','" pass "')")))))

(defn user-exist?
 ([user] (user-exist? user (common/coon)))

 ([{:keys [name pass]} coon]
  (let [stat (. coon createStatement)

        resultSet (. stat executeQuery
                     (str "select count(1) from user where name='" name "' and pass='" pass "'"))
        count (do
               (. resultSet next)
               (. resultSet getInt 1))]
      
       (> count 0))))